import api from './index'

// 登录
export const login = (credentials) => {
  return api.post('/auth/login', credentials)
}

// 注册
export const register = (userData) => {
  return api.post('/auth/register', userData)
}

// 登出
export const logout = () => {
  return api.post('/auth/logout')
}

// 检查登录状态
export const checkAuth = () => {
  return api.get('/auth/check')
}

// 生成邀请码
export const generateInviteCode = (options = {}) => {
  return api.post('/auth/generate-invite', options)
}

// 获取邀请码列表
export const getInviteCodes = () => {
  return api.get('/auth/invite-codes')
}

// 获取用户自己的邀请码列表
export const getMyInviteCodes = () => {
  return api.get('/auth/my-invite-codes')
}

// 获取用户列表
export const getUsers = () => {
  return api.get('/auth/users')
}

// 更新用户权限
export const updateUserPermissions = (userId, permissions) => {
  return api.put(`/auth/user/${userId}/permissions`, permissions)
}

// 切换全局邀请权限
export const toggleAllowAllInvite = (allowAllInvite) => {
  return api.put('/auth/system/allow-all-invite', { allowAllInvite })
}

// 获取系统配置
export const getSystemConfig = () => {
  return api.get('/auth/system/config')
}

// 获取邀请码统计信息
export const getInviteStats = () => {
  return api.get('/auth/invite-stats')
}

// 批量删除邀请码
export const deleteInviteCodesBatch = (ids) => {
  return api.delete('/auth/invite-codes/batch', { data: { ids } })
}

// 清理过期邀请码
export const cleanupExpiredInviteCodes = () => {
  return api.post('/auth/invite-codes/cleanup')
}

// 验证邀请码
export const validateInviteCode = (code) => {
  return api.post('/auth/validate-invite', { code })
}